namespace CSW.Framework.Common.Binding.Interfaces
{
    /// <summary>
    /// IBusinessObject interface.
    /// </summary>
    public interface IBusinessObject : IBindableObject
    {
        /// <summary>
        /// Gets a value indicating whether this instance is in edit mode.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is in edit mode; otherwise, <c>false</c>.
        /// </value>
        bool IsEditting { get; }

        /// <summary>
        /// Refreshes this instance from the database.
        /// </summary>
        void Refresh();

        /// <summary>
        /// Tries to save the record to the database.
        /// </summary>
        /// <returns><c>true</c> if successful; otherwise, <c>false</c>.</returns>
        bool TrySave();

        /// <summary>
        /// Deletes the record from the database.
        /// </summary>
        void Delete();

        /// <summary>
        /// Tries to save the record to the database.
        /// </summary>
        /// <param name="errorMessage">The error message.</param>
        /// <returns><c>true</c> if successful; otherwise, <c>false</c>.</returns>
        bool TrySave(out string errorMessage);

        /// <summary>
        /// Begins edit mode.
        /// </summary>
        void BeginEdit();

        /// <summary>
        /// Begins edit mode.
        /// </summary>
        /// <param name="refresh"><c>true</c> to refresh the object from the database; <c>false</c> to leave in current state (default = true).</param>
        void BeginEdit(bool refresh);

        /// <summary>
        /// Cancels edit mode.
        /// </summary>
        void CancelEdit();

        /// <summary>
        /// Determines whether the object is new (not saved to the database).
        /// </summary>
        /// <returns><c>true</c> if this instance is new; otherwise, <c>false</c>.</returns>
        bool IsNew { get; }
    }
}